package com.rongcheng.fortestlist.view;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import com.rongcheng.fortestlist.R;
import com.rongcheng.fortestlist.Utils;

public class ViewActivity extends AppCompatActivity {
    static String TAG = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TAG = this.getClass().getSimpleName();
        setContentView(R.layout.activity_view);
        TextView tv_test = (TextView) findViewById(R.id.tv_view);


        tv_test.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        int[] locationXY = new int[2];
                        view.getLocationOnScreen(locationXY);

                        Log.e(TAG, "x:" + Utils.pxTodip(ViewActivity.this, locationXY[0]) + "dp         " + "y:" + Utils.pxTodip(ViewActivity.this, locationXY[1]) + "dp");
                        Log.e(TAG,"getX :"+view.getX() +"getY :"+view.getY());
                        //单点触摸   0
                        break;
                    case MotionEvent.ACTION_UP:
                        //单点触摸离开动作   1

                        break;
                    case MotionEvent.ACTION_MOVE:
                        //触摸点移动  2

                        break;
                    case MotionEvent.ACTION_CANCEL:
                        //触摸动作取消 3
                        break;
                    case MotionEvent.ACTION_OUTSIDE:
                        //触摸动作超出边界 4

                        break;
                    case MotionEvent.ACTION_POINTER_DOWN:
                        //多点触摸按下动作 5

                        break;
                    case MotionEvent.ACTION_POINTER_UP:
                        //多点触摸离开6

                        break;
                }

                return false;
            }
        });
    }

}
